#ifndef TREEFILE_H_INCLUDED
#define TREEFILE_H_INCLUDED

#include <stdlib.h>
#include <stdint.h>

#include "fmap.h"
#include "reporting.h"

#define TREEFILE_ERRCODE_BASE           (37700)
#define TREEFILE_ERR_OPEN_FAILED        (TREEFILE_ERRCODE_BASE + 1)
#define TREEFILE_ERR_INVALID_MAX_DEPTH  (TREEFILE_ERRCODE_BASE + 2)
#define TREEFILE_ERR_TOO_DEEP           (TREEFILE_ERRCODE_BASE + 3)
#define TREEFILE_ERR_TOO_SHALLOW        (TREEFILE_ERRCODE_BASE + 4)


typedef struct _treefile_t {
	int            fd;
	int            max_depth;
	int            curr_level;
	off_t *        offsets_stack;
	fwindow_t      head;
	fmap_t         jumper;
} treefile_t;


#ifdef TREEFILE_INLINE_ALL
#define TREEFILE_STATIC static
#include "treefile.c"
#else
#define TREEFILE_STATIC
int treefile_init(treefile_t * self, int fd, int max_depth);
int treefile_fini(treefile_t * self);
int treefile_enter(treefile_t * self, const void * payload,
		uint16_t payload_size);
int treefile_leave(treefile_t * self, const void * extra_payload,
		uint16_t extra_payload_size);
int treefile_open(treefile_t * self, const char * filename, int max_depth);
int treefile_close(treefile_t * self);
#endif


#endif /* TREEFILE_H_INCLUDED */
